package com.bilibili.api;

import com.bilibili.api.support.UserSupport;
import com.bilibili.domain.JsonResponse;
import com.bilibili.domain.annotation.ApiLimitedRole;
import com.bilibili.domain.annotation.DataLimited;
import com.bilibili.domain.constant.AuthRoleConstant;
import com.bilibili.domain.entity.UserMoments;
import com.bilibili.service.UserMomentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * projectName:com.bilibili.api
 *
 * @author 飞
 * @create by 2024/6/914:40
 * description:
 */
@Api(tags = "动态管理")
@RestController
public class UserMomentController {
    @Resource
    private UserMomentsService userMomentsService;
    @Resource
    private UserSupport userSupport;

    @ApiLimitedRole(limitedRoleCodeList = {AuthRoleConstant.ROLE_LV0})
    @DataLimited
    @PostMapping("/user-moments")
    @ApiOperation("新增用户动态")
    public JsonResponse<String> addUserMoments(@RequestBody UserMoments userMoments) throws MQBrokerException, RemotingException, InterruptedException, MQClientException {
        Long userId = userSupport.getCurrentUserId();
        userMoments.setUserId(userId);
        userMomentsService.addUserMoments(userMoments);
        return JsonResponse.success();
    }

    @GetMapping("/user-subscribed-moments")
    @ApiOperation("查询用户动态")
    public JsonResponse<List<UserMoments>> getUserSubscribedMoments(){
        Long userId = userSupport.getCurrentUserId();
        List<UserMoments> list = userMomentsService.geyUserSubscribedMoments(userId);
        return new JsonResponse<>(list);
    }
}
